<?php

function formate($string, $type = "name") {
    switch ($type) {
        case "":
    }
    return $string;
}

$str = '<tr><td>暂无数据</td></tr>';
//  输入非手机号或物流编号或订单编号时输出
$id = (isset($_GET['id']) && $_GET['id']) ? intval($_GET['id']) : 0;
if (isset($_GET['query']) && !empty($_GET['query']) || ($id > 0)) {
    // 判断前台输入的值是否为空，不为空时则执行
//FIXME;
    if ($_GET['query']) {
        $where = "(mobile_phone ='{$_GET['query']}' or order_nu = '{$_GET['query']}' or invoice_nu ='{$_GET['query']}')   and creat_time >='" . date("y-m-d H:i:s", strtotime("-1month")) . "'   AND STATE>=0";
    } else {
        $where = "  STATE>=0";
    }
    if ($id > 0) {
        $where .= " and id=$id ";
    }
    // 查询的条件 判断输入的值是否与手机号，物流编号，订单编号相同并且状态大于等于0
    $result = $GLOBALS['db']->where($where)->select(OrderInfo::TABLE_NAME);
    //  数据库的查询，在数据库查询，
//    echo $GLOBALS['db']->getLastSql();
//    die;
//    echo "<pre>";
//    var_dump($result);

    if (count($result) > 0) {
        $str = "";
        foreach ($result as $key => $value) {
            $str .= '<table class="detail-table">';
            $str .= "<tr>";
            $str .= "<th>";
            $str .= "姓名";
            $str .= '</th>';
            $str .= "<td>";
            $str .= formate($value['user_name']);
            $str .= '</td>';
            $str .= "</tr>";

            $str .= "<tr>";
            $str .= "<th>";
            $str .= "手机号";
            $str .= '</th>';
            $str .= "<td>";
            $str .= formate($value['mobile_phone']);
            $str .= '</td>';
            $str .= "</tr>";

            $str .= "<tr>";
            $str .= "<th>";
            $str .= "订单编号";
            $str .= '</th>';
            $str .= "<td>";
            $str .= formate($value['order_nu']);
            $str .= '</td>';
            $str .= "</tr>";

            $str .= "<tr>";
            $str .= "<th>";
            $str .= "商品名称";
            $str .= '</th>';
            $str .= "<td>";
            $str .= formate($value['goods_name']);
            $str .= '</td>';
            $str .= "</tr>";

            $str .= "<tr>";
            $str .= "<th>";
            $str .= "数量";
            $str .= '</th>';
            $str .= "<td>";
            $str .= formate($value['goods_nu']);
            $str .= '</td>';
            $str .= "</tr>";
            $str .= "<tr>";
            $str .= "<th>";
            $str .= "快递公司";
            $str .= '</th>';
            $str .= "<td>";
            $str .= formate($value['invoice_name']);
            $str .= '</td>';
            $str .= "</tr>";

            if ($value["invoice_nu"]) {
                $str .= "<tr>";
                $str .= "<th>";
                $str .= "快递编号";
                $str .= '</th>';
                $str .= "<td>";
                $str .= formate($value['invoice_nu']);
                $str .= "<a class='btn' href=\"javascript:loadExpress('{$value['invoice_name']}','{$value['invoice_nu']}','invoce_reslut_{$key}');\">查看物流</a>";
                $str .= '</td>';
                $str .= "</tr>";
            }
            if ($value['address']) {
                //  if语句表示当值为空时，页面不显示地址这一栏
                $str .= "<tr>";
                $str .= "<th>";
                $str .= "地址";
                $str .= '</th>';
                $str .= "<td>";
                $str .= formate($value['address']);
                $str .= '</td>';
                $str .= "</tr>";
            }
            if ($value['remark']) {
                //  if语句表示当值为空时，页面不显示备注这一栏
                $str .= "<tr>";
                $str .= "<th>";
                $str .= "备注";
                $str .= '</th>';
                $str .= "<td>";
                $str .= formate($value['remark']);
                $str .= '</td>';
                $str .= "</tr>";
            }

            $str .= "</table>";
            $str .= "<div id='invoce_reslut_{$key}'></div>";
        }
    }
}
include_once LIBRARY_PATH . "wechat.class.php";

$weixinclass = new \core_lib_wechat($options);
$signPackage = $weixinclass->getSignPackage();

$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$imgUrl = "$protocol$_SERVER[HTTP_HOST]/Static/images/loginicon.png";
//
//$url = "http://express.aixianxing.com";
//$imgUrl = "http://express.aixianxing.com/Static/images/loginicon.png";

$sharedata = array(
    "link" => $url,
    "desc" => "点击查询链民菜市订单物流",
    "imgUrl" => $imgUrl,
    "title" => "链民菜市信息查询",
);
$wechartData = array(
    'sharedata' => $sharedata,
    'signPackage' => $signPackage,
);
?>

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1" />
        <link rel="shortcut icon" href="/favicon.ico" />
        <meta name="description" content="链民菜市订单物流查询">
        <title>链民菜市订单物流查询</title>

        <link href="/Static/css/base.css" rel="stylesheet" type="text/css">
        <link href="/Static/css/express.css" rel="stylesheet" type="text/css">
        <script src="/Static/js/jquery-1.9.1.min.js"></script>
    </head>
    <style>

        a{text-decoration:none;}

        .content{
            max-width: 700px;
            margin-left: auto;
            margin-right: auto;
        }
        .btn.btn-b {
            position: relative;
            top: 3px;
        }

        .entering {
            height: 34px;
            margin-top: 10px;
            text-align: center;
        }

        .entering .input {
            height: 34px;
            width: 215px;
        }

        .detail {
            margin-top: 10px;
        }

        .detail .detail-table {
            border-bottom: 1px solid #008000;
            padding: 10px 5px;
        }
        .detail-table tr:nth-of-type(2n){

            background: #f8f8f8;
        }
        .detail-table th {
            text-align: right;
            width: 80px;
            padding: 10px 0px;
            color:#333333;
        }

        .detail-table td {
            padding-left: 10px;
            text-align: left;
            color: #666666;
        }

        .header {
            height: 50px;
            background: #c1c1c1;
            box-shadow: 1px 1px #ececec;
            color: #008000;
            line-height: 50px;
            text-align: center;
        }
        .header-logo {
            width: 83px;
            position: absolute;
            left: 17px;
            top: 6px;
        }


        .bodycover {
            width: 100%;
            left: 0;

            height: 100%;
            top: 0;

            position: fixed;
            z-index: 999;
            background: #000000;
            opacity: 0.5;
            font-size: 12px !important;

        }
        .alert-content{
            padding: 5px 0px;
            position: fixed;
            width: 94%;
            z-index: 99999;
            background: #ffffff;
            left: 3%;
            top: 10%;
            height: 80%;
            overflow-y: scroll;
            border: 1px solid #8BC34A;
            border-radius: 5px;
            box-shadow: 1px 1px #4CAF50;
        }
    </style>

    <body>
        <div class="content">

            <div class="header">
                <img class="header-logo" src="/Static/images/logo.png" >
                <span class="poll">链民菜市订单物流查询</span>
            </div>
            <div style="    color: #000000;padding: 5px;text-align: center;">
                仅能查询最近30日内的数据
            </div>
            <div class="total">
                <div class="entering">


                    <form method="get" action="">
                        <input type="text" class="input" placeholder="请输入手机号或物流编号或订单编号"  name="query"/>
                        <input class="btn btn-b" type="submit" value="提交">
                    </form>
                </div>
                <div class="detail">

                    <?php echo $str ?>

                </div>
            </div>
            <div>


            </div>

    </body>

    <script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
    <script>

        wx.config({
            debug: false,
            appId: '<?php echo $wechartData['signPackage']['appId']; ?>',
            timestamp: <?php echo $wechartData['signPackage']['timestamp']; ?>,
            nonceStr: '<?php echo $wechartData['signPackage']['nonceStr']; ?>',
            signature: '<?php echo $wechartData['signPackage']['signature']; ?>',
            jsApiList: [
                // 所有要调用的 API 都要加到这个列表中
                "onMenuShareTimeline",
                "onMenuShareAppMessage",
                "showOptionMenu",
                "hideMenuItems",
                "showMenuItems",
                "hideAllNonBaseMenuItem"
            ]
        });
        wx.ready(function () {
            wx.hideAllNonBaseMenuItem();

            wx.showMenuItems({
                menuList: [
                    "menuItem:share:appMessage",
                    "menuItem:share:timeline",
                    "menuItem:favorite"
                ] // 要显示的菜单项，所有menu项见附录3
            });

            //获取“分享到朋友圈”按钮点击状态及自定义分享内容接口
            wx.onMenuShareTimeline({
                title: '<?php echo $wechartData['sharedata']['desc']; ?>', // 分享标题
                link: '<?php echo $wechartData['sharedata']['link']; ?>', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                imgUrl: '<?php echo $wechartData['sharedata']['imgUrl']; ?>', // 分享图标
                success: function () {
                    // 用户确认分享后执行的回调函数
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            });
            //获取“分享给朋友”按钮点击状态及自定义分享内容接口
            wx.onMenuShareAppMessage({
                title: '<?php echo $wechartData['sharedata']['title']; ?>', // 分享标题
                link: '<?php echo $wechartData['sharedata']['link']; ?>', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                desc: '<?php echo $wechartData['sharedata']['desc']; ?>', // // 分享描述
                imgUrl: '<?php echo $wechartData['sharedata']['imgUrl']; ?>', // 分享图标
                type: '', // 分享类型,music、video或link，不填默认为link
                dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                success: function () {
                    // 用户确认分享后执行的回调函数
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            });


        });
    </script>


    <script>
        function creatimgalert(content) {
            var str = "<div id='imagealert'>";
            str += '<div class="bodycover"></div>';
            str += '<div class="alert-content">';
            str += content;
            str += '</div>';
            str += '</div>';

            $("body").append(str);
            $("#imagealert").click(function () {
                removeimgalert("imagealert");
            });
        }

        function removeimgalert(id) {
            $("#" + id).remove();
        }
        function loadExpress(name, number, elemnentid) {

            $.getJSON("/index.php?m=Express&c=index&action=loadExpressAjax", {"invoice_name": name, "invoice_nu": number}, function (ret) {
                if (ret.success == false) {
                    alert("参数有误无法查询");
                } else {
                    if (ret.data.status == 200) {
                        var index = 0;
                        var length = ret.data.data.length;
                        var str = '<table  id="queryResult" class="result-info" cellspacing="0">';
                        for (index = 0; index < length; index++) {
                            if (index == 0) {
                                str += '<tr class="last">';
                            } else {
                                str += '<tr>';
                            }
                            str += ' <td class="row1"><span class="day">' + ret.data.data[index].time + '</span></td>';
                            if (index == 0) {
                                str += ' <td class="status status-wait">&nbsp;<div class="col2"><span class="step"><span class="line1"></span><span class="line2"></span></span></div></td>';
                            } else {
                                str += ' <td class="status">&nbsp;<div class="col2"><span class="step"><span class="line1"></span><span class="line2"></span></span></div></td>';
                            }

                            str += '<td class="context">' + ret.data.data[index].context + '</td>';
                            str += '</tr>';
                        }
                        str += '</table>';
                        creatimgalert(str);
//                        $("#" + elemnentid).html(str);

//                        setTimeout(scrollToEnd, 100);
                    } else {
                        alert(ret.data.message);
                    }

                }
            })
        }

        var scrollToEnd = function () {//滚动到底部
            var h = $(document).height() - $(window).height();

            $(document).scrollTop(h);
        }
    </script>
</html>
